[#macro notifierListView]
<div>
    <el-dialog title="添加通知者" :visible.sync="addVisible" width="30%">
        <el-form ref="notifierForm" :rules="notifierRules" :model="notifierForm" label-width="100px">
            <el-form-item label="通知人" prop="name" size="mini">
                <el-input v-model="notifierForm.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="OpenId" prop="openId" size="mini">
                <el-input v-model="notifierForm.openId" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="addVisible = false">取 消</el-button>
            <el-button type="primary" @click="addnotifier">确 定</el-button>
        </span>
    </el-dialog>

    <el-dialog title="添加通知者" :visible.sync="addQrVisible" width="30%">
        <img :src="qrUrl" style="height: 100px;width: 100px;">
        <span slot="footer" class="dialog-footer">
            <el-button @click="addQrVisible = false">取 消</el-button>
            <el-button type="primary" @click="addQrVisible = false">确 定</el-button>
        </span>
    </el-dialog>

    
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
        <span>确认要删除该条数据吗?</span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleClose">确 定</el-button>
        </span>
    </el-dialog>
    <div class="data-content1">
        <div  class="tool-add" style="margin-top: 20px;">
            <el-button type="primary" size="small" @click="addView">新增</el-button>

            <el-button type="primary" size="small" @click="addQrView">二维码绑定</el-button>

        </div>
        <el-table v-loading="loading" :data="tableData.list" @cell-click="showView" @sort-change="changeTableSort"
            style="font-size: 12px;">
            <el-table-column label="名称"   prop="name" width="200">
            </el-table-column>
            <el-table-column label="通知人OpenId"   prop="openId" width="260">
            </el-table-column>
            <el-table-column label="添加时间"  prop="addDate" >
            </el-table-column>
            <el-table-column width="120" align="center" fixed="right" label="操作">
                <template slot-scope="scope">
                    <el-button type="text" size="mini" icon="el-icon-info" @click="test(scope.row)">测试
                    </el-button>
                     <el-button type="text" icon="el-icon-delete" class="danger" size="mini" style="cursor: pointer;"
                            @click="deleteData(scope.row)">删除
                     </el-button>                   
                </template>
            </el-table-column>
        </el-table>

        <div class="page">
            <el-pagination background :current-page="searchObject.no" :page-sizes="[10, 20, 50, 100]"
                :page-size="tableData.size" :pager-count="5" layout="total, sizes, prev, pager, next, jumper"
                :page-count="tableData.totalPage" :total="tableData.total" @size-change="sizeChange"
                @current-change="pageChange">
            </el-pagination>
        </div>
    </div>
</div>
[/#macro]
[#macro notifierListConfig]
<script type="text/x-template" id="my-notifier-list">
	[@notifierListView /]
</script>
<script type="text/javascript">
    var notifierListConfig = {};
    notifierListConfig.template = "#my-notifier-list";
    notifierListConfig.methods = config.basicMethod();


    notifierListConfig.methods.addView = function () {
       this.addVisible=true;
    }
    notifierListConfig.methods.addQrView = function () {
       this.addQrVisible=true;
       this.qrUrl="${siteurl}bind_code/3/"+this.selectId+".htm";
    }
    

    notifierListConfig.methods.auditView = function (row) {
        this.selectData = row;
        this.auditVisible = true;
        this.form.name = row.name;
        this.form.logo = row.logo;
        this.form.id = row.id;

        this.form.auditState="";
    }


    notifierListConfig.methods.editView = function (row) {
        var self = this;
        var data = {};
        data.id = row.id;
        this.$router.push({ path: 'update', query: data });

    }

    notifierListConfig.methods.changeTableSort = function (column) {
        this.searchObject.sortField = column.prop;
        if ("descending" == column.order) {
            this.searchObject.sortMethod = "desc";
        }
        else if ("ascending" == column.order) {
            this.searchObject.sortMethod = "asc";
        }
        else {
            this.searchObject.sortMethod = "";
        }
        this.getSearchList();
    }
    notifierListConfig.methods.showView = function (row, column, cell, event) {
        if (cell.cellIndex >= 0) {
            return;
        }
        var param = {};
        param.id = row.id;
        var self = this;
        this.$router.push({ path: 'view', query: param });

    }
    notifierListConfig.methods.show = function (row) {
        var param = {};
        param.id = row.id;
        var self = this;
        this.$router.push({ path: 'view', query: param });

    }

    notifierListConfig.methods.handleSelect = function (index) {
        if (index == "1") {
            this.searchObject.auditState = "checked"
        } else if (index == "2") {
            this.searchObject.auditState = "wait"
        } else if (index == "3") {
            this.searchObject.auditState = "fail"
        } else {
            this.searchObject.auditState = ""
        }
        this.activeIndex = index;
        this.getSearchList();
    }

    notifierListConfig.methods.sizeChange = function (event) {
        this.searchObject.size = event;
        this.getSearchList();
    }
    notifierListConfig.methods.pageChange = function (index) {
        this.searchObject.no = index;
        this.getSearchList();
    }
    notifierListConfig.methods.getSearchList = function () {
        this.loading = true;
        var data = this.searchObject, that = this;
        $.post("${siteurl}tenantRest/shopnotifier/search.htm", data, function (result) {
            if (result.code == 0) {
                that.tableData = result;
            }
            setTimeout(function () {
                that.loading = false;
            }, 300)
        });
    }
    notifierListConfig.methods.search = function () {
        this.searchObject.no = 1;
        this.getSearchList();
    }
    notifierListConfig.methods.clearData = function () {
        this.searchObject.shop =this.selectId;
    }
    notifierListConfig.methods.addnotifier = function () {
        var self=this;
        this.$refs["notifierForm"].validate(function (valid) {
			if (valid) {
				self.addnotifierData();
			} else {
				console.log('error submit!!');
				return false;
			}
		});
    }
    
    notifierListConfig.methods.addnotifierData = function () {
        var self = this, data = this.notifierForm;
		if (this.deforeAddData) {
			this.deforeAddData();
		}
		this.postData("${siteurl}tenantRest/shopnotifier/create.htm", data, function (res) {
			if (res.code == 0) {
				self.$message({
					message: '添加数据成功',
					type: 'success'
				});
				self.getSearchList();
                self.addVisible=false;

			} else {
				self.$message.error(res.msg);
			}
		});
    }
    notifierListConfig.methods.test = function (row) {
        var self = this;
        var param={};
        param.id=row.id;

		this.postData("${siteurl}tenantRest/shopnotifier/test.htm", param, function (res) {
			if (res.code == 0) {
				self.$message({
					message: '测试成功',
					type: 'success'
				});
			} else {
				self.$message.error(res.msg);
			}
		});
    }


    

    notifierListConfig.methods.deleteData = function (event) {
        this.selectDataId = event.id;
        this.dialogVisible = true;
    }

    notifierListConfig.methods.handleClose = function (done) {
        this.dialogVisible = false;
        var self = this;
        if (self.selectDataId) {
            var params = {};
            params.id = self.selectDataId;
            this.postData("${siteurl}tenantRest/shopnotifier/delete.htm", params, function (res) {
                if (res.code == 0) {
                    self.$message({
                        message: '删除数据成功',
                        type: 'success'
                    });
                    self.getSearchList();
                } else {
                    self.$message.error(res.msg);
                }
            });
        }

    }

    notifierListConfig.computed = {};

    notifierListConfig.data = function () {
        return {
            searchObject: {
                no: 1,
                size: 10,
                shop:""
            },
            dialogVisible: false,
            addQrVisible:false,
            auditVisible: false,
            defaultProps: {
                children: 'children',
                label: 'name'
            },
            loading: false,
            addVisible:false,
            tableData: {},
            activeIndex: "1",
            form: {
                logo: '',
                openId: '',
                notifierCatalog: '',
                sortNum: '',
                boss: '',
                address: '',
                tel: '',
                auditState:""
            },
            notifierForm:{},
            pickeOptions: {
                start: '00:00',
                step: '00:15',
                end: '23:50'
            },
            rules: {
                name: [
                    { required: true, message: '请输入商家名称', trigger: 'blur' }
                ],
            },
            notifierRules: {
                name: [
                    { required: true, message: '请输入名称', trigger: 'blur' }
                ],
                openId: [
                    { required: true, message: '请输入OpenId', trigger: 'blur' }
                ],
                
            }
        }
    };
    notifierListConfig.mounted = function () {
        var id = this.$route.query.id;
        this.selectId = id;
        this.notifierForm.shop=id;
        this.searchObject.shop =this.selectId;
        this.getSearchList();
    }
    var notifierListView = Vue.component('list-notifier-view', notifierListConfig);
</script>
[/#macro]